package string

/**
 * Groovy中的字符串可以用单引号（'），双引号（“）或三引号（”“”）括起来。‘
 * 此外，由三重引号括起来的Groovy字符串可以跨越多行。
 * 更多字符操作 可以看源码 结构
 */
class Strings {

    static def method1(){
        String a = 'Hello Single';
        String b = "Hello Double";
        String c = "'Hello Triple" + "Multiple lines'";

        println(a);
        println(b);
        println(c);
    }

    static def method2(){
        String sample = "Hello world";

        println(sample[4]); // Print the 5 character in the string

        //Print the 1st character in the string starting from the back
        println(sample[-1]);
        println(sample[1..2]);//Prints a string starting from Index 1 to 2
        println(sample[4..2]);//Prints a string starting from Index 4 back to 2
    }

    static void main(String[] args) {
        method1()
        method2()
    }
}
